package com.fpx.open.platform.domain.exception;

import java.util.HashMap;
import java.util.Map;

import com.fpx.open.platform.common.constant.ErrorCodeConstant;


/**
 * 服务层异常类
 * @author sunkey
 * @date Mar 15, 2013 6:32:59 PM
 * @version 1.0.0 
 * @copyright fpx.com 
 */
@SuppressWarnings("serial")
public class ServiceException extends Exception {
	
	private final Map<String,Object> info = new HashMap<String,Object>();
    private String errorCode = ErrorCodeConstant.E_0103;
    private String message;
    private Object[] object;


    /**
     * @param message the exception message
     * @param cause the exception that cause this exception to be thrown
     */
    public ServiceException(String message, Throwable cause)
    {
    	super(message, cause);
        this.message = message;
    }
    public ServiceException(String message)
    {
    	super(message);
    	this.message = message;
    }
    
    public ServiceException(String message, String errorCode)
    {
    	super(message);
    	this.message = message;
    	this.errorCode = errorCode;
    }

    public ServiceException(Throwable cause)
    {
        super(cause);
    }

    protected ServiceException()
    {
        super();
    }

    public void setErrorCode(String errorCode)
    {
    	this.errorCode = errorCode;
    }
    
    public String getErrorCode()
    {
        return errorCode;
    }


	public void addInfo(String name, Object info)
    {
        this.info.put(name, info);
    }
    
	public void addAll(Map<String,Object> map)
    {
    	this.info.putAll(map);
    }
	
    public void appendMessage(String s)
    {
    	if(message == null){
    		message = s;
    	}else {
    		message += s;
    	}
    }

    protected void prependMessage(String s)
    {
        message = message + ". " + s;
    }

    @Override
    public final String getMessage()
    {
    	if(message==null) {
    		message = super.getMessage();
    	}
        return message;
    }

    public String getDetailedMessage()
    {
    	
    	return null;
    }

	public Map<String,Object> getInfo()
    {
        return info;
    }
	public Object[] getObject() {
		return object;
	}
	public void setObject(Object[] object) {
		this.object = object;
	}
    
    
}
